/*
 * Copyright (C) 2012 Realtek Semiconductor Corp.
 * All Rights Reserved.
 *
 * This program is the proprietary software of Realtek Semiconductor
 * Corporation and/or its licensors, and only be used, duplicated,
 * modified or distributed under the authorized license from Realtek.
 *
 * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
 * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
 *
 */


#include "app_basic.h"

MIB_TABLE_INFO_T gMibCucOnuCapabilityTableInfo;
MIB_ATTR_INFO_T  gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ATTR_NUM];
MIB_TABLE_CUC_ONUCAPABILITY_T gMibCucOnuCapabilityDefRow;
MIB_TABLE_OPER_T gMibCucOnuCapabilityOper;


static GOS_ERROR_CODE omci_mib_cuc_onuCapability_oper_reset(UINT32 args_num, ...)
{

    MIB_TABLE_CUC_ONUCAPABILITY_T       cucOnuCap;

    OMCI_LOG(OMCI_LOG_LEVEL_INFO, "Resetting MIB CUC ONU-CAP ME");
    MIB_Default(MIB_TABLE_CUC_ONUCAPABILITY_INDEX, &cucOnuCap, sizeof(MIB_TABLE_CUC_ONUCAPABILITY_T));
    cucOnuCap.EntityID       = 0x0000;
    GOS_ASSERT(GOS_OK == MIB_Set(MIB_TABLE_CUC_ONUCAPABILITY_INDEX, &cucOnuCap, sizeof(MIB_TABLE_CUC_ONUCAPABILITY_T)));
    OMCI_MeOperCfg(MIB_TABLE_CUC_ONUCAPABILITY_INDEX, NULL, &cucOnuCap, MIB_ADD,
        omci_GetOltAccAttrSet(MIB_TABLE_CUC_ONUCAPABILITY_INDEX, OMCI_ME_ATTR_ACCESS_SBC), OMCI_MSG_BASELINE_PRI_LOW);

    return GOS_OK;
}


GOS_ERROR_CODE mibTable_init(MIB_TABLE_INDEX tableId)
{
    UINT8 proprietary_mib_cb_bitmask = 0;
    UINT8 isIgnore = 0;
    if(GOS_OK == omci_ignore_mib_table_check(OMCI_ME_CLASS_CUC_ONU_CAPABILITY, OMCI_ME_CLASS_SUB_DEFAULT, &isIgnore))
    {
        if(isIgnore)
        {
	        OMCI_PRINT("Ignore classId:%d", OMCI_ME_CLASS_CUC_ONU_CAPABILITY);
            return GOS_FAIL;
        }

    }

    gMibCucOnuCapabilityTableInfo.Name = "CucOnuCapability";
    gMibCucOnuCapabilityTableInfo.ShortName = "CUC_ONUCAP";
    gMibCucOnuCapabilityTableInfo.Desc = "CUC_ONU capability";
    gMibCucOnuCapabilityTableInfo.ClassId = OMCI_ME_CLASS_CUC_ONU_CAPABILITY;
    gMibCucOnuCapabilityTableInfo.InitType = (UINT32)(OMCI_ME_INIT_TYPE_ONU);
    gMibCucOnuCapabilityTableInfo.StdType = (UINT32)(OMCI_ME_TYPE_PROPRIETARY);
    gMibCucOnuCapabilityTableInfo.ActionType = (UINT32)(OMCI_ME_ACTION_GET);
    gMibCucOnuCapabilityTableInfo.pAttributes = &(gMibCucOnuCapabilityAttrInfo[0]);

	gMibCucOnuCapabilityTableInfo.attrNum = MIB_TABLE_CUC_ONUCAPABILITY_ATTR_NUM;
	gMibCucOnuCapabilityTableInfo.entrySize = sizeof(MIB_TABLE_CUC_ONUCAPABILITY_T);
	gMibCucOnuCapabilityTableInfo.pDefaultRow = &gMibCucOnuCapabilityDefRow;

    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Name = "EntityId";
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_OPERATIONID_INDEX - MIB_TABLE_FIRST_INDEX].Name = "OperationId";
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUCSPEC_VERSION_INDEX - MIB_TABLE_FIRST_INDEX].Name = "CucSpecVer";
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].Name = "OnuType";
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_TXPWR_SUPPLY_CTRL_INDEX - MIB_TABLE_FIRST_INDEX].Name = "TxPwrSupplyCtrl";
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUSTOMIZED_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].Name = "CustomizedOnuType";

    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Entity ID";
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_OPERATIONID_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Operator ID";
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUCSPEC_VERSION_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "CUC Spec Version";
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "ONU Type";
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_TXPWR_SUPPLY_CTRL_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Tx Power Supply Control";
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUSTOMIZED_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Customized ONU Type";

    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_OPERATIONID_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_STR;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUCSPEC_VERSION_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_TXPWR_SUPPLY_CTRL_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUSTOMIZED_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;

    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_OPERATIONID_INDEX - MIB_TABLE_FIRST_INDEX].Len = 4;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUCSPEC_VERSION_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_TXPWR_SUPPLY_CTRL_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUSTOMIZED_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;

    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = TRUE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_OPERATIONID_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUCSPEC_VERSION_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_TXPWR_SUPPLY_CTRL_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUSTOMIZED_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;

    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_OPERATIONID_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUCSPEC_VERSION_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_TXPWR_SUPPLY_CTRL_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUSTOMIZED_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;

    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_OPERATIONID_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_CHAR;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUCSPEC_VERSION_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_TXPWR_SUPPLY_CTRL_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUSTOMIZED_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;

    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_OPERATIONID_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUCSPEC_VERSION_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_TXPWR_SUPPLY_CTRL_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUSTOMIZED_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;

    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_OPERATIONID_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUCSPEC_VERSION_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_TXPWR_SUPPLY_CTRL_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUSTOMIZED_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;

    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_OPERATIONID_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUCSPEC_VERSION_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_TXPWR_SUPPLY_CTRL_INDEX- MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibCucOnuCapabilityAttrInfo[MIB_TABLE_CUC_ONUCAPABILITY_CUSTOMIZED_ONU_TYPE_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_PRIVATE;

    memset(&gMibCucOnuCapabilityDefRow, 0x00, sizeof(gMibCucOnuCapabilityDefRow));
    snprintf(gMibCucOnuCapabilityDefRow.OperationId, MIB_TABLE_CUC_ONUCAPABILITY_OPERATIONID_LEN, "CUC");
    gMibCucOnuCapabilityDefRow.CucSpecVer = CUC_ONUCAPABILITY_CUC_GPON_V6;
    gMibCucOnuCapabilityDefRow.OnuType = CUC_ONUCAPABILITY_HGU_ONU_TYPE;
    gMibCucOnuCapabilityDefRow.TxPwrSupplyCtrl = CUC_ONUCAPABILITY_SUPPORT_TXRX_PWR_CTRL;

    memset(&gMibCucOnuCapabilityOper, 0x0, sizeof(MIB_TABLE_OPER_T));
    gMibCucOnuCapabilityOper.meOperDrvCfg = NULL;
    gMibCucOnuCapabilityOper.meOperConnCheck = NULL;
    gMibCucOnuCapabilityOper.meOperDump = omci_mib_oper_dump_default_handler;
	gMibCucOnuCapabilityOper.meOperConnCfg = NULL;
    gMibCucOnuCapabilityOper.meOperCb[PROPRIETARY_MIB_CB_RESET] = omci_mib_cuc_onuCapability_oper_reset;

	MIB_TABLE_CUC_ONUCAPABILITY_INDEX = tableId;
    MIB_InfoRegister(tableId, &gMibCucOnuCapabilityTableInfo, &gMibCucOnuCapabilityOper);

    proprietary_mib_cb_bitmask = (1 << PROPRIETARY_MIB_CB_RESET);
    MIB_Proprietary_Reg(tableId, proprietary_mib_cb_bitmask);

    return GOS_OK;
}

